<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1987-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation.  A copy of
the license is included in the
section entitled "GNU Free Documentation License".

This manual contains no Invariant Sections.  The Front-Cover Texts are
(a) (see below), and the Back-Cover Texts are (b) (see below).

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Undefining and Redefining Macros (The C Preprocessor)</title>

<meta name="description" content="Undefining and Redefining Macros (The C Preprocessor)">
<meta name="keywords" content="Undefining and Redefining Macros (The C Preprocessor)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Index-of-Directives.html" rel="index" title="Index of Directives">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Macros.html" rel="up" title="Macros">
<link href="Directives-Within-Macro-Arguments.html" rel="next" title="Directives Within Macro Arguments">
<link href="Predefined-Macros.html" rel="prev" title="Predefined Macros">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Undefining-and-Redefining-Macros">
<div class="nav-panel">
<p>
Next: <a href="Directives-Within-Macro-Arguments.html" accesskey="n" rel="next">Directives Within Macro Arguments</a>, Previous: <a href="Predefined-Macros.html" accesskey="p" rel="prev">Predefined Macros</a>, Up: <a href="Macros.html" accesskey="u" rel="up">Macros</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Undefining-and-Redefining-Macros-1"><span>3.8 Undefining and Redefining Macros<a class="copiable-link" href="#Undefining-and-Redefining-Macros-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-undefining-macros"></a>
<a class="index-entry-id" id="index-redefining-macros"></a>
<a class="index-entry-id" id="index-_0023undef"></a>

<p>If a macro ceases to be useful, it may be <em class="dfn">undefined</em> with the
&lsquo;<samp class="samp">#undef</samp>&rsquo; directive.  &lsquo;<samp class="samp">#undef</samp>&rsquo; takes a single argument, the
name of the macro to undefine.  You use the bare macro name, even if the
macro is function-like.  It is an error if anything appears on the line
after the macro name.  &lsquo;<samp class="samp">#undef</samp>&rsquo; has no effect if the name is not a
macro.
</p>
<div class="example smallexample">
<pre class="example-preformatted">#define FOO 4
x = FOO;        &rarr; x = 4;
#undef FOO
x = FOO;        &rarr; x = FOO;
</pre></div>

<p>Once a macro has been undefined, that identifier may be <em class="dfn">redefined</em>
as a macro by a subsequent &lsquo;<samp class="samp">#define</samp>&rsquo; directive.  The new definition
need not have any resemblance to the old definition.
</p>
<p>However, if an identifier which is currently a macro is redefined, then
the new definition must be <em class="dfn">effectively the same</em> as the old one.
Two macro definitions are effectively the same if:
</p><ul class="itemize mark-bullet">
<li>Both are the same type of macro (object- or function-like).
</li><li>All the tokens of the replacement list are the same.
</li><li>If there are any parameters, they are the same.
</li><li>Whitespace appears in the same places in both.  It need not be
exactly the same amount of whitespace, though.  Remember that comments
count as whitespace.
</li></ul>

<p>These definitions are effectively the same:
</p><div class="example smallexample">
<pre class="example-preformatted">#define FOUR (2 + 2)
#define FOUR         (2    +    2)
#define FOUR (2 /* <span class="r">two</span> */ + 2)
</pre></div>
<p>but these are not:
</p><div class="example smallexample">
<pre class="example-preformatted">#define FOUR (2 + 2)
#define FOUR ( 2+2 )
#define FOUR (2 * 2)
#define FOUR(score,and,seven,years,ago) (2 + 2)
</pre></div>

<p>If a macro is redefined with a definition that is not effectively the
same as the old one, the preprocessor issues a warning and changes the
macro to use the new definition.  If the new definition is effectively
the same, the redefinition is silently ignored.  This allows, for
instance, two different headers to define a common macro.  The
preprocessor will only complain if the definitions do not match.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Directives-Within-Macro-Arguments.html">Directives Within Macro Arguments</a>, Previous: <a href="Predefined-Macros.html">Predefined Macros</a>, Up: <a href="Macros.html">Macros</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index-of-Directives.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
